import { View, Image, Button } from "@tarojs/components"
import Taro, { useShareAppMessage } from '@tarojs/taro'
import { AtIcon, AtFloatLayout } from 'taro-ui'
import { useEffect,useState } from "react";
import NavBar from "../../components/topbar/topbar";
//import moment from "moment";
//import Date from "../../components/date/date";
import { Current } from '@tarojs/runtime';
//import huabao from "../firstPage/image/shouye.png";
//import left from "./image/left.png";
import right from "./image/right.png";
import line from "./image/line.png";
import hengxian from "./image/hengxian.png";
import WeChat from "./image/WeChat.png";
import shareCard from "./image/shareCard.png";
import './todayPush.scss'

function todayPush() {

    const [isOpen, setOpen] = useState(false)
    const [isRight, setRight] = useState(true)
    //获取首页中的每日推荐信息
    const [toDay_list1, setoDay_list1_tList1] = useState([{}])
    console.log("每日推荐中的数据:toDay_list1:", JSON.parse(decodeURIComponent(Current.router.params.value)))
    // 获取路由传参，并事实数据传递(同步)
    useEffect(() => {
        let data = JSON.parse(decodeURIComponent(Current.router.params.value))
        setoDay_list1_tList1([data])
    }, [])
    console.log("今日画报中的数据:", toDay_list1)


    const handleClick = data => {
        //向details传递数据
        let value1 = JSON.stringify(data)
        Taro.navigateTo({
            url: '/pages/details/details?value1='+encodeURIComponent(value1)
        })
    }
    /* const handleClick1 = () => {
        Taro.navigateTo({
            url: '/pages/firstPage/firstPage'
        })
    } */
    const toBack = () => {
        Taro.navigateBack().then()
    }
    const handleClick2 = () => {
        Taro.navigateTo({
            url: '/pages/shareCard/shareCard'
        })
    }

    useShareAppMessage(res => {
        if (res.from === 'button') {
            // 来自页面内转发按钮
            console.log(res.target)
        }
        return {
            title: '自定义转发标题',
            path: '/page/user?id=123'
        }
    })

    const changeOpen = () => {
        setOpen(true)
    }
    const changeRight = () => {
        setRight(!isRight)
    }
    let myDate=new Date()
    let year=myDate.getFullYear();
    let month=myDate.getMonth()+1;
    let date=myDate.getDate();
    let time = year+"年"+month+"月"+date+"日";
    console.log(time);
    return (
        <View>
            <View className="huabao">
                <NavBar title="我的今日画报" back nback={toBack} />
                <View className="xiangqing">
                    <View className="zanping">
                        <View className="zanpic">快乐宝贝，快乐宝贝。</View>
                        <View className="zantext">今日，了解什么呢？</View>
                        <Image className="hengxian" src={hengxian} />
                    </View>
                </View>
                <Image className="pic" src={toDay_list1[0].picture} />
                <View className="date">
                    {/* {baodate2chinese(moment().format('YYYY-MM-DD'))} <Date />*/}
                    {time=year+"年"+month+"月"+date+"日"}
                </View>
                <View onClick={()=>{handleClick(toDay_list1[0])}}>
                    <View className="pictext">
                        {
                            toDay_list1[0].recommended_title
                        }
                    </View>
                    <Image className="line" src={line} />
                    <Image className="right" src={right} />
                    <View className="picknow">详情</View>
                </View>
                {/* <AtIcon className="message" value='message' size='25' color='#000'></AtIcon> */}
                <View onClick={() => { changeRight() }}>
                    {isRight ? (
                        <AtIcon className="heart" value='heart' size='23' color='#000' />
                    ) : (
                        <AtIcon className="heart" value='heart-2' size='23' color='#f00' />
                    )}
                    <View className="hearText" >点赞</View>
                </View>
                <View>
                    <View onClick={() => changeOpen()}>
                        <AtIcon className="share" value='share' size='23' color='#000'></AtIcon>
                        <View className="sharetext" >分享</View>
                    </View>
                    <AtFloatLayout isOpened={isOpen}>
                        <View className="sharebox">
                            <Button className="sFriend" openType="share">
                                <Image className="WeChat" src={WeChat} />
                                <View className="WeChatText">分享给微信好友</View>
                            </Button>
                            <Button className="sCard" onClick={handleClick2}>
                                <Image className="shareCard" src={shareCard} />
                                <View className="WeChatText">生成分享卡</View>
                            </Button>
                        </View>
                        <Button className="cancel" onClick={() => setOpen(false)}>取消</Button>
                    </AtFloatLayout>
                </View>
            </View>
        </View>
    )
}
export default todayPush
